﻿using System;
using System.Globalization;
using System.Windows.Data;
using Dsl.Ped.Framework.Common;
using Dsl.Ped.Framework.WPFControls.ProjectiveObject;

namespace Dsl.Ped.Common.Converters
{
    /// <summary>
    /// Converter of the <see cref="ProjectiveObjectUserControl"/> into the <see cref="IProjective"/>
    /// </summary>
    public class ProjectiveObjectConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Convert the <see cref="ProjectiveObjectUserControl"/> into the <see cref="IProjective"/>
        /// </summary>
        /// <param name="value">ProjectiveObjectUserControl instnace to be converted</param>
        /// <param name="targetType">Target type of the conversion</param>
        /// <param name="parameter">Parameter of the conversion</param>
        /// <param name="culture">Culture under which the conversion is done</param>
        /// <returns>ProjectiveObject converted from the ProjectiveObjectUserControl</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ProjectiveObjectUserControl)
            {
                var itemContainer = (ProjectiveObjectUserControl)value;
                return itemContainer.ProjectiveObject;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
